package com.situ.hr4.w.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.hr4.pojo.*;
import com.situ.hr4.w.service.JLGLservice;
import com.situ.hr4.w.service.ZWFBservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//简历管理
@Controller
public class JLGLcontroller {
    //时间类型转换器
    @InitBinder  //
    public void dateconvert(WebDataBinder bind){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        PropertyEditor n=new CustomDateEditor(format, true);
        bind.registerCustomEditor(java.sql.Date.class, n);
    }

    @Autowired
    JLGLservice jlgL;

    @Autowired
    ZWFBservice zwfb;

    //简历登记
    @RequestMapping("a3")
    public String a3(Map map){
        //职位分类查询,绑
        List<ConfigMajorKind> zwfl=zwfb.cxzwfl();
        map.put("zwfl",zwfl);
        //国籍
        List<ConfigPublicChar> gj=jlgL.cxxgsj("国籍");
        map.put("gj",gj );
        //民族
        List<ConfigPublicChar> mz=jlgL.cxxgsj("民族");
        map.put("mz",mz );
        //宗教信仰
        List<ConfigPublicChar> zjxy=jlgL.cxxgsj("宗教信仰");
        map.put("zjxy",zjxy );
        //政治面貌
        List<ConfigPublicChar> zzmm=jlgL.cxxgsj("政治面貌");
        map.put("zzmm",zzmm );
        //学历
        List<ConfigPublicChar> xl=jlgL.cxxgsj("学历");
        map.put("xl",xl);
        //教育年限
        List<ConfigPublicChar> jynx=jlgL.cxxgsj("教育年限");
        map.put("jynx",jynx );
        //专业
        List<ConfigPublicChar> xlzy=jlgL.cxxgsj("专业");
        map.put("xlzy",xlzy);
        //特长
        List<ConfigPublicChar> tc=jlgL.cxxgsj("特长");
        map.put("tc",tc);
        //爱好
        List<ConfigPublicChar> ah=jlgL.cxxgsj("爱好");
        map.put("ah",ah);
        return "/page/recruit/resume/resume-register.html";
    }

    //从职位发布查询跳转到简历登记
    @PostMapping("Wtzjldj")
    public String Wtzjldj(int id,Map map){
        //System.out.println(id);
        //通过id找
        Map m=jlgL.queryid(id);
        map.put("m",m );
        //通过相关类型查询相关数据
        //国籍
        List<ConfigPublicChar> gj=jlgL.cxxgsj("国籍");
        map.put("gj",gj );
        //民族
        List<ConfigPublicChar> mz=jlgL.cxxgsj("民族");
        map.put("mz",mz );
        //宗教信仰
        List<ConfigPublicChar> zjxy=jlgL.cxxgsj("宗教信仰");
        map.put("zjxy",zjxy );
        //政治面貌
        List<ConfigPublicChar> zzmm=jlgL.cxxgsj("政治面貌");
        map.put("zzmm",zzmm );
        //学历
        List<ConfigPublicChar> xl=jlgL.cxxgsj("学历");
        map.put("xl",xl);
        //教育年限
        List<ConfigPublicChar> jynx=jlgL.cxxgsj("教育年限");
        map.put("jynx",jynx );
        //专业
        List<ConfigPublicChar> xlzy=jlgL.cxxgsj("专业");
        map.put("xlzy",xlzy);
        //特长
        List<ConfigPublicChar> tc=jlgL.cxxgsj("特长");
        map.put("tc",tc);
        //爱好
        List<ConfigPublicChar> ah=jlgL.cxxgsj("爱好");
        map.put("ah",ah);
        return "/page/recruit/resume/register.html";
    }
    //添加简历
    @PostMapping("Wtjjl")
    public String Wtjjl(EngageResume ers){
        //System.out.println("id:"+ers.getHuman_major_id());
        ers.setCheck_status(1);
        jlgL.tjjl(ers);
        return  "redirect:a4";
    }






    //简历筛选
    @RequestMapping("a4")
    public String a4(Map map){
        //职位分类查询,绑
        List<ConfigMajorKind> zwfl=zwfb.cxzwfl();
        map.put("zwfl",zwfl);
        return "/page/recruit/resume/resume-choose.html";
    }

    //跳转到复核页面
    @RequestMapping("Wa")
    public String Wa(int id,Map map){
       // System.out.println(id);
        //通过简历的职位名称id查询
        Map m=jlgL.zwmcid(id);
        //通过id查询简历信息
        EngageResume ers=jlgL.jlxxid(id);
        //java.text.SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        //String s=sdf.format(ers.getHuman_birthday());
        //System.out.println(ers.getHuman_birthday());
        map.put("e",ers);
        map.put("m", m);
        return "/page/recruit/resume/resume-details.html";
    }

    @RequestMapping("Wa1")
    public String Wa1(EngageResume er,Map m,
                      @RequestParam(defaultValue = "1",required = false) Integer startPage,
                      @RequestParam(defaultValue = "3",required = false) Integer PageSize){
        String sql="select res_id,human_name,human_sex,major_kind_name,major_name,human_mobilephone,check_status from engage_resume a,config_major_kind b,config_major c where a.human_major_id=c.major_id and c.major_kind_id=b.major_kind_id ";
        Map map=new HashMap();
        //System.out.println(er.getHuman_major_id());
        if(er.getHuman_major_id()!=null) {
            //System.out.println(1);
            if (er.getHuman_major_id() != 0) {
                //System.out.println("进入下拉框");
                //System.out.println(er.getHuman_major_id());
                sql = sql + " and human_major_id=#{a}";
                map.put("a", er.getHuman_major_id());
            }
            if (!er.getGjz().equals("")) {
                //System.out.println("进入关键字");
                //System.out.println(1);
                sql = sql + " and human_name like #{a1}";
                map.put("a1", '%' + er.getGjz() + '%');
            }
            if (!er.getDate1().equals("") || !er.getDate2().equals("")) {
                //System.out.println("时间");
                sql = sql + " and regist_time between #{date1} and #{date2} ";
                map.put("date1", er.getDate1());
                map.put("date2", er.getDate2());
            }
        }
        //System.out.println(1);
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        map.put("sql",sql );
        //System.out.println(map.get("sql"));
        List<Map> l=jlgL.jlsxcx(map);
        PageInfo pageInfo=new PageInfo(l, 3); //保存分页信息
        //System.out.println("1:"+l.size());
        m.put("list",l );
        m.put("pageInfo", pageInfo); //绑定分页信
        m.put("e", er);
        //System.out.println(m.get("e"));
        return "/page/recruit/resume/resume-list.html";
    }




    //有效简历查询

    //推荐跳转到有效简历查询和添加
    @RequestMapping("Wa4")
    public String Wa4(EngageResume er,Map map){
        //向简历表添加推荐人、推荐时间、推荐意见
        er.setCheck_status(2);
        jlgL.updatejlb(er);
        //职位分类查询,绑
        List<ConfigMajorKind> zwfl=zwfb.cxzwfl();
        map.put("zwfl",zwfl);
        return "/page/recruit/resume/valid-resume.html";
    }

    //直接跳转到有效查询
    @RequestMapping("a5")
    public String a5(Map map){
        //职位分类查询,绑
        List<ConfigMajorKind> zwfl=zwfb.cxzwfl();
        map.put("zwfl",zwfl);
        return "/page/recruit/resume/valid-resume.html";
    }

    //有限简历查询
   @RequestMapping("Wa3")
    public String Wa3(EngageResume ers,Map m,
                      @RequestParam(defaultValue = "1",required = false) Integer startPage,
                      @RequestParam(defaultValue = "3",required = false) Integer PageSize) {
       String sql = "select res_id,human_name,human_sex,major_kind_name,major_name,human_mobilephone,check_status from engage_resume a,config_major_kind b,config_major c where a.human_major_id=c.major_id and c.major_kind_id=b.major_kind_id and check_status=2";
       Map map = new HashMap();
       //System.out.println(er.getHuman_major_id());
       if(ers.getHuman_major_id()!=null){
           //System.out.println(1);
           if (ers.getHuman_major_id() != 0) {
               //System.out.println("进入下拉框");
               //System.out.println(er.getHuman_major_id());
               sql = sql + " and human_major_id=#{a}";
               map.put("a", ers.getHuman_major_id());
           }
           if (!ers.getGjz().equals("")) {
               //System.out.println("进入关键字");
               //System.out.println(1);
               sql = sql + " and human_name like #{a1}";
               map.put("a1", '%' + ers.getGjz() + '%');
           }
           if (!ers.getDate1().equals("") || !ers.getDate2().equals("")) {
               //System.out.println("时间");
               sql = sql + " and regist_time between #{date1} and #{date2} ";
               map.put("date1", ers.getDate1());
               map.put("date2", ers.getDate2());
           }
       }
       //System.out.println(1);
       PageHelper.startPage(startPage, PageSize ); //使用分页插件
       map.put("sql",sql );
       //System.out.println(map.get("sql"));
       List<Map> l=jlgL.jlsxcx(map);
       PageInfo pageInfo=new PageInfo(l, 3); //保存分页信息
       //System.out.println("1:"+l.size());
       m.put("list",l );
       m.put("pageInfo", pageInfo); //绑定分页信
       m.put("e", ers);
        return "/page/recruit/resume/valid-list.html";
    }

    //跳转到详细
    @RequestMapping("Wa2")
    public String Wa2(int id,Map map){
        //通过简历的职位名称id查询
        Map m=jlgL.zwmcid(id);
        //通过id查询简历信息
        EngageResume ers=jlgL.jlxxid(id);
        map.put("e",ers);
        map.put("m", m);
        return "/page/recruit/resume/resume-select.html";
    }
}
